package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysClientWeightCount;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysClientWeight;
import com.ruoyi.system.service.ISysClientWeightService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 智能称重记录Controller
 * 
 * @author spark
 * @date 2023-08-13
 */
@RestController
@RequestMapping("/system/weight")
public class SysClientWeightController extends BaseController
{
    @Autowired
    private ISysClientWeightService sysClientWeightService;

    @PreAuthorize("@ss.hasPermi('system:weight:count')")
    @GetMapping("/count")
    public TableDataInfo count(SysClientWeight sysClientWeight)
    {
        startPage();
        List<SysClientWeightCount> list = sysClientWeightService.selectSysClientWeightCount(sysClientWeight);
        return getDataTable(list);
    }

    /**
     * 查询智能称重记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:weight:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysClientWeight sysClientWeight)
    {
        startPage();
        List<SysClientWeight> list = sysClientWeightService.selectSysClientWeightList(sysClientWeight);
        return getDataTable(list);
    }


    /**
     * 导出智能称重统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:weight:countExport')")
    @Log(title = "智能称重统计记录", businessType = BusinessType.EXPORT)
    @PostMapping("/countExport")
    public void countExport(HttpServletResponse response, SysClientWeight sysClientWeight)
    {
        List<SysClientWeightCount> list = sysClientWeightService.selectSysClientWeightCount(sysClientWeight);
        ExcelUtil<SysClientWeightCount> util = new ExcelUtil<SysClientWeightCount>(SysClientWeightCount.class);
        util.exportExcel(response, list, "智能称重统计数据");
    }


    /**
     * 导出智能称重记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:weight:export')")
    @Log(title = "智能称重记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysClientWeight sysClientWeight)
    {
        List<SysClientWeight> list = sysClientWeightService.selectSysClientWeightList(sysClientWeight);
        ExcelUtil<SysClientWeight> util = new ExcelUtil<SysClientWeight>(SysClientWeight.class);
        util.exportExcel(response, list, "智能称重记录数据");
    }

    /**
     * 获取智能称重记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:weight:query')")
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") Long dataId)
    {
        return success(sysClientWeightService.selectSysClientWeightByDataId(dataId));
    }

    /**
     * 新增智能称重记录
     */
    @PreAuthorize("@ss.hasPermi('system:weight:add')")
    @Log(title = "智能称重记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysClientWeight sysClientWeight)
    {
        return toAjax(sysClientWeightService.insertSysClientWeight(sysClientWeight));
    }

    /**
     * 修改智能称重记录
     */
    @PreAuthorize("@ss.hasPermi('system:weight:edit')")
    @Log(title = "智能称重记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysClientWeight sysClientWeight)
    {
        return toAjax(sysClientWeightService.updateSysClientWeight(sysClientWeight));
    }

    /**
     * 删除智能称重记录
     */
    @PreAuthorize("@ss.hasPermi('system:weight:remove')")
    @Log(title = "智能称重记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable Long[] dataIds)
    {
        return toAjax(sysClientWeightService.deleteSysClientWeightByDataIds(dataIds));
    }
}
